from alg import Solution, validate_pancake_sort
from gen import load_test_cases
import time

def run_tests():
    # 加载测试用例
    test_cases = load_test_cases()
    solution = Solution()
    total_cases = len(test_cases)
    passed_cases = 0
    
    print(f"Running tests on {total_cases} cases...")
    print("=" * 50)
    
    for i, case in enumerate(test_cases, 1):
        print(f"Test case {i}: {case}")
        
        # 记录开始时间
        start_time = time.time()
        
        # 执行煎饼排序
        k_sequence = solution.pancakeSort(case.copy())
        
        # 记录结束时间
        end_time = time.time()
        
        # 验证结果
        is_valid = validate_pancake_sort(case, k_sequence)
        
        # 输出结果
        if is_valid:
            print(f"✓ Passed (Time: {(end_time - start_time)*1000:.2f}ms)")
            print(f"Flip sequence: {k_sequence}")
            passed_cases += 1
        else:
            print("✗ Failed")
        
        print("-" * 50)
    
    print("=" * 50)
    print(f"Test results: {passed_cases}/{total_cases} passed")
    print(f"Success rate: {passed_cases/total_cases*100:.2f}%")

if __name__ == "__main__":
    run_tests()